package com.lzx.guanchajava.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.databinding.library.baseAdapters.BR
import androidx.recyclerview.widget.RecyclerView

class CommonListAdapter<T: Any>(@LayoutRes private val layoutId: Int): RecyclerView.Adapter<CommonListHolder>() {
    val data = mutableListOf<T>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommonListHolder {
        return CommonListHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.context), layoutId, parent, false))
    }

    override fun onBindViewHolder(holder: CommonListHolder, position: Int) {
        holder.binding.setVariable(BR.data, data[position])
    }

    override fun getItemCount() = data.size
}